home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0896.zip / WAMPLER.ZIP / DRAWCMDW.CXX < prev    next >
C/C++ Source or Header  |  1996-05-24  |  6KB  |  188 lines

  1.  
  2. //================================================================
  3. //  drawcmdw.cxx:     Source file for drawApp cmdwin class
  4. //  Copyright (C) 1995  Bruce E. Wampler
  5. //================================================================
  6. #include <v/include/vnotice.h>  // so we can use notice
  7. #include <v/include/vpen.h>     // for drawing pen
  8. #include <v/include/vfilesel.h> // for file selection
  9.  
  10. #include "drawcmdw.h"   // our header
  11.  
  12. //   Start defines for the main window with 100
  13.  
  14. const ItemVal m_Clear = 100;
  15. const ItemVal m_LineWidth = 101;
  16. const ItemVal m_ChangePen = 102;
  17.  
  18. static vMenu FileMenu[] =    // File pulldown menu
  19.   {
  20.     {"New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
  21.     {"Open", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
  22.     {"Save", M_Save, isSens, notChk, noKeyLbl, noKey, noSub},
  23.     {"Save As", M_SaveAs, isSens,notChk,noKeyLbl,noKey,noSub},
  24.     {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  25.     {"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
  26.     {NULL}
  27.   };
  28. static vMenu EditMenu[] =    // Edit menu
  29.   {
  30.     {"Clear", m_Clear, isSens, notChk, noKeyLbl, noKey,noSub},
  31.     {NULL}
  32.   };
  33. vMenu MainMenu[] =           // Main menu
  34.   {
  35.     {"File",M_File,isSens,notUsed,notUsed,noKey,&FileMenu[0]},
  36.     {"Edit",M_Edit,isSens,notUsed,notUsed,noKey,&EditMenu[0]},
  37.     {NULL}
  38.   };
  39.  
  40. // Define the command bar
  41. static int minMaxStep[3] = {1, 20, 1};    // for line width
  42. static CommandObject CommandBar[] =
  43.   {
  44.     {C_Button, m_Clear, m_Clear, "Clear", NoList,
  45.             CA_None,isSens,NoFrame,0,0},
  46.     {C_Label, 999, 0 ," Pen Width: ", NoList,
  47.             CA_None, isSens, NoFrame,0,0},
  48.     {C_ValueBox,m_LineWidth,1,"",(void*)&minMaxStep[0],
  49.             CA_None,isSens,NoFrame,0,0},
  50.     {C_Label, 999, 0, " Pen Color: ",NoList,
  51.             CA_None,isSens,NoFrame,0,0},
  52. #define vC_Size 12              // size of color buttons
  53. #include <v/include/vcb2x8.h>   // define a color selection box
  54.     {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  55.   };
  56.  
  57. //================>>> myCmdWindow::myCmdWindow <<<================
  58. myCmdWindow::myCmdWindow(char* name, int height, int width) :
  59.   vCmdWindow(name, height, width)
  60. {
  61.   // Create and add the proper panes to the CmdWindow
  62.  
  63.   *_fname = 0;                        // no name
  64.  
  65.   myMenu = new vMenuPane(MainMenu);   // Add the main menu
  66.   AddPane(myMenu);
  67.  
  68.   myCanvas = new myCanvasPane;        // Add the canvas pane
  69.   AddPane(myCanvas);
  70.  
  71.   myCmdPane = new vCommandPane(CommandBar); // Add command pane
  72.   AddPane(myCmdPane);
  73.  
  74.   ShowWindow();           // FINALLY, we must show the window!
  75. }
  76.  
  77. //===============>>> myCmdWindow::~myCmdWindow <<<================
  78. myCmdWindow::~myCmdWindow()
  79. {
  80.   delete myMenu;      // Delete everything new'ed in
  81.   delete myCanvas;    //   the constructor
  82.   delete myCmdPane;
  83. }
  84.  
  85. //==============>>> myCmdWindow::WindowCommand <<<================
  86. void myCmdWindow::WindowCommand(ItemVal id, ItemVal val,
  87.       CmdType cType)
  88. {
  89.   // route all commands through here - menus and buttons
  90.  
  91.   static char* filter[] = {"*.drw","*", 0};   // file filter
  92.   int fi = 0;                  // filter index
  93.   vNoticeDialog note(this);    // for user notification
  94.  
  95.   switch (id)                  // switch on id of commands
  96.     {
  97.       case M_New:
  98.         {
  99.           // call our NewAppWin method
  100.           theApp->NewAppWin(0,"V Draw - No Name",250,500,0);
  101.           break;
  102.         }
  103.  
  104.       case M_Open:
  105.         {
  106.           if (*_fname)
  107.             {
  108.               note.Notice("Create a New window first.");
  109.               break;
  110.             }
  111.  
  112.           vFileSelect fsel(this);     // V file select dialog
  113.  
  114.           if (!fsel.FileSelect("Open V Draw File",
  115.             _fname,99,filter,fi) || !*_fname)
  116.               break;                  // ignore if no selection
  117.  
  118.           if (!myCanvas->Read(_fname)) // Save in _fname
  119.             {
  120.               note.Notice("Unable to read file");
  121.               break;
  122.             }
  123.           SetTitle(_fname);           // show on title bar
  124.           myCanvas->Redraw(0,0,0,0);  // paint it
  125.           break;
  126.         }
  127.  
  128.       case M_Save:
  129.         {
  130.           if (*_fname)                 // have a name
  131.             {
  132.               if (!myCanvas->Save(_fname)) // Save in _fname
  133.                   note.Notice("Unable to save file");
  134.               break;
  135.             }
  136.           // else fall through to SaveAs
  137.         }
  138.  
  139.       case M_SaveAs:
  140.         {
  141.           vFileSelect fsel(this);     // V file select dialog
  142.  
  143.           if (!fsel.FileSelect("Save V Draw File As",
  144.             _fname,99,filter,fi) || !*_fname)
  145.               break;                  // ignore if no selection
  146.  
  147.           if (!myCanvas->Save(_fname)) // Save in _fname
  148.             {
  149.               note.Notice("Unable to read file");
  150.               break;
  151.             }
  152.           SetTitle(_fname);
  153.           break;
  154.         }
  155.  
  156.       case M_Exit:
  157.         {
  158.           theApp->Exit();       // Standard action for Exit
  159.           break;
  160.         }
  161.  
  162.       case m_LineWidth:
  163.         {
  164.           _pen.penWidth = val;        // set new pen width
  165.           myCanvas->SetPen(_pen);
  166.           break;
  167.         }
  168.  
  169.       case m_Clear:                  // clear the screen
  170.         {
  171.           myCanvas->Clear();
  172.           break;
  173.         }
  174.  
  175.       default:                       // change pen color?
  176.         {
  177.           if (id >= M_Black && id <= M_White)  // color button
  178.             {
  179.               _pen.penColor = vStdColors[val];
  180.               myCanvas->SetPen(_pen);
  181.             }
  182.           else                      // pass up hierarchy
  183.               vCmdWindow::WindowCommand(id, val, cType);
  184.           break;
  185.         }
  186.     }
  187. }
  188.